---
title: "Direct_mail_meta_analysis"
author: "Jose S. Gomez"
date: "8/12/2023"
output: html_document
---


```{r, setup, include=FALSE}
rm(list=ls())       # clear objects in memory
knitr::opts_knit$set(root.dir = '/Users/gomez/Library/CloudStorage/Dropbox/GOTV V/Replication Files/Data') #Set Working Directory
```

#setup clean working environment, packages and data
```{r}
library(tidyverse)
library(foreign) 
library(metafor) # meta-analysis package

mail_data <- read.csv("GOTV V Direct Mail Data (Overall Collapsed).csv")
mail_data <- subset(mail_data, studynum != 790) #excluding walking the walk (only affects overall results)
mail_data <- subset(mail_data, studynum != 791)

#coding election year for pres vs. non-pres meta skip if you would like overall results
pres <- filter(mail_data, mail_data$pres == 1)
nonpres <- filter(mail_data, mail_data$pres == 0)
```

#Appendix B estimates in order of thier appearance within the book:
```{r}
#Non-partisan mailers that do not invoke social pressure
rma(yi = Meta_b[Advocacy != 1 & SocialPressure == 0 &studynum != 141 &studynum != 142], 
    sei= Meta_SE[Advocacy != 1 & SocialPressure == 0 &studynum != 141 &studynum != 142],
    method = "DL", 
    data= mail_data) 

############non advocacy no soft social pressure no gratitude ################

rma(yi = Meta_b[Advocacy == 0 & SocialPressure == 0 & SoftSocialPressure == 0 & Gratitude == 0 &studynum != 141 &studynum != 142],
    sei= Meta_SE[Advocacy == 0 & SocialPressure == 0 & SoftSocialPressure == 0 & Gratitude == 0 &studynum != 141 &studynum != 142 ],
    method = "DL", 
    data= mail_data)

#advocacy mailers that do not invoke social pressure
rma(yi = Meta_b[Advocacy == 1 & SocialPressure == 0 & studynum != 17], 
    sei= Meta_SE[Advocacy == 1 & SocialPressure == 0 & studynum != 17], 
    method = "DL", 
    data= mail_data)  

#Pooled social pressure estimates 
rma(yi = Meta_b[SocialPressure == 1], 
    sei= Meta_SE[SocialPressure == 1], 
    method = "DL", 
    data= mail_data) 

#Gratitude
rma(yi = Meta_b[Gratitude == 1],
    sei= Meta_SE[Gratitude == 1],
    method = "DL", 
    data= mail_data)

#additional analyses not in appendix tables
#Pooled non presidential election experiments
rma(yi = Meta_b[SocialPressure == 0 & Advocacy == 0], 
    sei= Meta_SE[SocialPressure == 0 & Advocacy == 0], 
    method = "DL", 
    data= nonpres) 

#Pooled non presidential election experiments
rma(yi = Meta_b[SocialPressure == 0 & Advocacy == 0], 
    sei= Meta_SE[SocialPressure == 0 & Advocacy == 0], 
    method = "DL", 
    data= pres) 
```